package com.cch.cooperation.api.common.config;

import com.getui.push.v2.sdk.ApiHelper;
import com.getui.push.v2.sdk.GtApiConfiguration;
import com.getui.push.v2.sdk.api.PushApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import javax.annotation.Resource;


/**
 * 个推客户端配置
 *
 * @author cch
 */
@Slf4j
@Configuration
public class GeTuiConfiguration {

    @Resource
    private Environment environment;

    @Bean
    public PushApi pushApi() {
        try {
            System.setProperty("http.maxConnections", "200");
            GtApiConfiguration configuration = new GtApiConfiguration();
            configuration.setAppId(environment.getProperty("app.ge-tui.app-id"));
            configuration.setAppKey(environment.getProperty("app.ge-tui.app-key"));
            configuration.setMasterSecret(environment.getProperty("app.ge-tui.master-secret"));
            configuration.setDomain(environment.getProperty("app.ge-tui.domain"));
            return ApiHelper.build(configuration).creatApi(PushApi.class);
        } catch (Exception e) {
            log.warn("个推客户端初始化失败: {}", e.getMessage());
            return null;
        }
    }
}
